package com.ruoyi.cfuser.rescue.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitDelayConfig {
    /*
    * 1、声明正常交换机(task_exchange)和正常队列(task_queue)，并绑定
    * */
    @Bean
    public Exchange taskExchange() {
        return
        ExchangeBuilder.topicExchange("task_exchange").durable(true).build();
    }

    @Bean
    public Queue taskQueue() {
    /*
    * 3、正常队列绑定死信交换机
    * */
    return QueueBuilder.durable("task_queue")
    // 正常队列绑定死信交换机: deadLetterExchange 死信交换机名称deadLetterRoutingKey
            .deadLetterExchange("task_dlx_exchange").deadLetterRoutingKey("task.dlx.cancel")
    // 4、设置队列的过期时间 30min
            .ttl(10 * 1000)
            .build();
    }

    @Bean
    public Binding bindingOrderNormal() {
        return
        BindingBuilder.bind(taskQueue()).to(taskExchange()).with("task.#").noargs();
    }

    /*
    * 2、声明死信交换机(order_dlx_exchange)和死信队列(order_dlx_queue)，并绑定
    * */
    @Bean
    public Exchange taskDlxExchange() {
        return
        ExchangeBuilder.topicExchange("task_dlx_exchange").durable(true).build();
    }
    @Bean
    public Queue taskDlxQueue() {
        return QueueBuilder.durable("task_dlx_queue").build();
    }
    @Bean
    public Binding bindingTaskDlx() {
        return
        BindingBuilder.bind(taskDlxQueue()).to(taskDlxExchange()).with("task.dlx.#").noargs();
    }
}